package com.liangtian.mdm.system.parameter.utils;

import com.liangtian.mdm.system.parameter.model.SysParameter;
import com.liangtian.mdm.system.parameter.service.SysParameterService;
import com.liangtian.mdm.util.SpringContextUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class SysParameters {

    private static SysParameters sysParameters;

    private Map<String, String> map = new HashMap<String, String>();

    private SysParameters() {
        //init();
    }

    public void init() {
        SysParameterService spm = SpringContextUtil.getBean(SysParameterService.class);
        List<SysParameter> list = spm.getParameterLst();
        if (list != null && list.size() > 0) {
            for (SysParameter sp : list) {
                map.put(sp.getParameterName(), sp.getParameterValue());
            }
        }
        //map.put("attchFileMaxSize", "123456");
    }

    public synchronized static SysParameters getInstance() {
        if (sysParameters == null) {
            sysParameters = new SysParameters();
        }
        return sysParameters;
    }

    public String getParameterByName(String name) {
        return map.get(name);
    }

//	public static void main(String[] args){
//		System.out.println(SysParameters.getInstance().getParameterByName("attchFileMaxSize"));
//	}
}
